<template>
  <!-- 横向 导航栏 -->
  <div class="page">
    <div class="header">
      <div class="logo">
        <img src="../../static/image/bigLogo.jpg" alt />
      </div>
      <div class="header-right">
        <div class="header-user-con">
          <!-- 用户头像 -->
          <div class="user-avator">
            <!-- <img src="../images/img.png" /> -->
            <i class="el-icon-user-solid"></i>
          </div>
          <!-- 用户名下拉菜单 -->
          <el-dropdown class="user-name" trigger="click" @command="handleCommand">
            <span class="el-dropdown-link">
              {{companyName}}
              <i class="el-icon-caret-bottom"></i>
            </span>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item command="seeMe">账号资料</el-dropdown-item>
              <!-- <el-dropdown-item>账户管理</el-dropdown-item>
              <el-dropdown-item>支付记录</el-dropdown-item>-->
              <!-- divided 线 -->
              <el-dropdown-item command="loginout">退出登录</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </div>
      </div>
      <el-menu
        :default-active="h_nav_v"
        class="menuNav"
        mode="horizontal"
        :unique-opened="true"
        @select="handleSelect"
      >
        <template v-for="(v,i) in navArr">
          <template v-if="v.subs">
            <el-submenu :index="i+''" :key="i">
              <template slot="title">{{v.txt}}</template>
              <template v-for="(vv,ii) in v.subs">
                <el-menu-item :index="vv.path" :key="i+'-'+ii">{{vv.txt}}</el-menu-item>
              </template>
            </el-submenu>
          </template>
          <template v-else>
            <el-menu-item :index="v.path" :key="i">{{v.txt}}</el-menu-item>
          </template>
        </template>
      </el-menu>
    </div>
    <!-- <vNav v-show="s_v_nav" :mold="mold" /> -->
    <div class="content-box">
      <el-backtop target=".content-box" :bottom="60"></el-backtop>
      <transition name="move" mode="out-in">
        <keep-alive :include="tagsList">
          <router-view :key="this.$route.path"></router-view>
        </keep-alive>
      </transition>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      h_nav_v: "",
      tagsList: [],
      s_v_nav: false,
      companyName: "",
      navArr: [
        {
          txt: "首页",
          path: "home",
        },
        {
          txt: "赛事/活动",
          path: "match",
        },
        // 营销推广 ==》 需设置权限可见 ==》 主针对热门赛事 热门活动 今日推荐 公司账号或内部人员可见 此推广并不是针对单个赛事
        // {
        //   txt: "营销/推广",
        //   path: "Marketing/banner",
        // },
        // {
        //   txt: "商品管理",
        //   path: "goods",
        // },
        {
          txt: "报名款统计",
          path: "money",
        },
        // {
        //   txt: "订单",
        //   //   path: "home",
        // },
        // {
        //   txt: "系统设置",
        //   //   path: "home",
        // },
      ],
    };
  },
  watch: {
    $route(to, from) {
      let o = this.$route.path.substring(1);
      let a = o.split("/")[0];
      let p = this.navArr.find((v) => {
        if (v.path.indexOf(a) >= 0) {
          return v.path;
        }
      });
      if (p) this.h_nav_v = p.path;
      else this.h_nav_v = "";
    },
  },
  methods: {
    // 用户名下拉菜单选择事件
    handleCommand(command) {
      if (command == "loginout") {
        // localStorage.removeItem('ms_username')
        this.$cookies.remove("user_session");
        this.$router.replace("/");
      } else if (command == "seeMe") {
        if (this.$route.path == "/account") return false;
        else this.$router.push("/account");
      }
    },
    power() {
      let uu = this.$cookies.get("user_session");
      uu = JSON.parse(this.$Base64.decode(uu));
      this.companyName = uu.companyName;
      if (uu.id == 1) {
        this.navArr.splice(
          2,
          0,
          {
            txt: "营销/推广",
            path: "Marketing/banner",
          },
          {
            txt: "商品管理",
            path: "goods",
          },{
            txt: "文章管理",
            path: "article",
          },
          {
            txt: "活动抽奖",
            path: "luck",
          },
        );
        this.navArr.push({
          txt: "合作伙伴",
          path: "partner",
        },{
          txt: "用户成绩管理",
          path: "gradeU",
        },);
      }
    },
    handleSelect(key, keyPath) {
      if (keyPath.length > 1) {
        this.$router.push("/" + keyPath[1]);
      } else {
        if ("/" + keyPath[0] == this.$route.path) return false;
        this.$router.push("/" + keyPath[0]);
      }
    },
  },
  created() {
    this.power();
    let o = this.$route.path.substring(1);
    let a = o.split("/")[0];
    let p = this.navArr.find((v) => {
      if (v.path.indexOf(a) >= 0) {
        return v.path;
      }
    });
    if (p) {
      this.h_nav_v = p.path;
    }
  },
};
</script>
<style scoped>
.page {
  width: 100%;
  height: 100%;
  overflow: hidden;
}
.header {
  width: 100%;
  height: 60px;
  overflow: hidden;
  position: fixed;
  background-color: #fff;
  top: 0;
  z-index: 10;
}
.logo {
  width: 200px;
  height: 60px;
  float: left;
}
.logo img {
  width: 100%;
  height: 100%;
}
.menuNav {
  float: left;
  margin-left: 20px;
}
.content-box {
  margin-top: 60px;
  background: #f2f2f2;
  height: calc(100% - 60px);
  overflow-y: auto;
  position: relative;
}
/* .content-box.lEmpty {
  width: calc(100% - 200px - 48px);
  margin-left: 200px;
  height: calc(100% - 60px - 32px);
  background-color: #edf0f6;
  padding: 16px 24px;
  min-height: auto;
} */

/*滚动条整体样式*/
.content-box::-webkit-scrollbar {
  width: 8px;
  height: 8px;
  background: #f2f2f2;
}
/*滚动条里面小方块*/
.content-box::-webkit-scrollbar-thumb {
  border-radius: 10px;
  box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.2);
  background: #b4bbc5;
}
/*滚动条里面轨道*/
.content-box::-webkit-scrollbar-track {
  box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.2);
  /* border-radius: 10px; */
  /* background: #ededed; */
  /* background: #60c5ff; */
}

/* 个人信息 */
.header-right {
  float: right;
  padding-right: 50px;
}
.header-user-con {
  display: flex;
  height: 70px;
  align-items: center;
}
.btn-fullscreen {
  transform: rotate(45deg);
  margin-right: 5px;
  font-size: 24px;
}
.btn-bell,
.btn-fullscreen {
  position: relative;
  width: 30px;
  height: 30px;
  text-align: center;
  border-radius: 15px;
  cursor: pointer;
}
.btn-bell-badge {
  position: absolute;
  right: 0;
  top: -2px;
  width: 8px;
  height: 8px;
  border-radius: 4px;
  background: #f56c6c;
  /* color: #fff; */
}
.user-name {
  margin-left: 10px;
}
.user-avator {
  margin-left: 20px;
}
.user-avator img {
  display: block;
  width: 40px;
  height: 40px;
  border-radius: 50%;
}
.el-dropdown-link {
  /* color: #fff; */
  cursor: pointer;
}
.el-dropdown-menu__item {
  text-align: center;
}
</style>